package com.itbaima.mapper;

import com.itbaima.pojo.VO.HrArchiveVO;
import com.itbaima.pojo.entity.HrArchive;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HumanMapper {

    /**
     * 录入档案信息
     * @param hrArchive
     */
    @Insert("INSERT INTO hr_archive " +
            "(department_level1_id, department_level2_id, department_level3_id, " +
            "department_name, department_id, name, gender, age, phone, " +
            "id_card, salary, bank_name, bank_account, personal_description, " +
            "remarks, registrar, registrar_id, registration_time, archive_code) " +
            "VALUES " +
            "(#{departmentLevel1Id}, #{departmentLevel2Id}, #{departmentLevel3Id}, " +
            "#{departmentName}, #{departmentId}, #{name}, #{gender}, #{age}, #{phone}, " +
            "#{idCard}, #{salary}, #{bankName}, #{bankAccount}, #{personalDescription}, " +
            "#{remarks}, #{registrar}, #{registrarId}, #{registrationTime}, #{archiveCode})")
    void insert(HrArchive hrArchive);


    /**
     * 根据所属部门名称，获得所属部门的ID
     * @param departmentName
     */
    @Select("select department_id from departments where department_name = #{departmentName}  ")
    Integer getDpId(String departmentName);

    /**
     * 获取所有人力资源档案信息
     *
     * @return
     */
    @Select("select * from hr_archive")
    List<HrArchiveVO> getAll();

    /**
     * 修改人力资源表的信息
     * @param hrArchiveVO
     */
    @Update("""
    UPDATE hr_archive 
    SET 
        department_level1_id = #{department_level1_id},
        department_level2_id = #{department_level2_id},
        department_level3_id = #{department_level3_id},
        department_name = #{department_name},
        department_id = #{department_id},
        name = #{name},
        gender = #{gender},
        age = #{age},
        phone = #{phone},
        id_card = #{id_card},
        salary = #{salary},
        bank_name = #{bank_name},
        bank_account = #{bank_account},
        personal_description = #{personal_description},
        remarks = #{remarks},
        registrar = #{registrar},
        registrar_id = #{registrar_id},
        registration_time = #{registration_time},
        archive_code = #{archive_code}
    WHERE id = #{id}
""")
    void update(HrArchiveVO hrArchiveVO);

    @Delete("delete from hr_archive where id = #{id} ")
    void delete(Integer id);


}
